package com.learning.platform.dto;

import com.learning.platform.entity.ExamRecord;
import com.learning.platform.enums.ExamRecordStatus;
import com.learning.platform.enums.PassStatus;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

public class ExamRecordResponse {
    private Long id;
    private Long examId;
    private String examTitle; // 考试标题
    private Long userId;
    private String userName; // 用户姓名
    private Integer attemptNumber;
    private LocalDateTime startTime;
    private LocalDateTime submitTime;
    private Integer timeSpent;
    private ExamRecordStatus status;
    private BigDecimal totalScore;
    private BigDecimal totalPoints;
    private BigDecimal percentage; // 得分百分比
    private PassStatus passStatus;
    private Boolean autoGraded;
    private Boolean manualGraded;
    private Long gradedBy;
    private String graderName; // 评分人姓名
    private LocalDateTime gradedAt;
    private String feedback;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    
    // 答案详情（用于查看考试结果）
    private List<ExamAnswerResponse> answers;
    
    // Constructors
    public ExamRecordResponse() {}
    
    public ExamRecordResponse(ExamRecord examRecord) {
        this.id = examRecord.getId();
        this.examId = examRecord.getExamId();
        this.userId = examRecord.getUserId();
        this.attemptNumber = examRecord.getAttemptNumber();
        this.startTime = examRecord.getStartTime();
        this.submitTime = examRecord.getSubmitTime();
        this.timeSpent = examRecord.getTimeSpent();
        this.status = examRecord.getStatus();
        this.totalScore = examRecord.getTotalScore();
        this.totalPoints = examRecord.getTotalPoints();
        this.passStatus = examRecord.getPassStatus();
        this.autoGraded = examRecord.getAutoGraded();
        this.manualGraded = examRecord.getManualGraded();
        this.gradedBy = examRecord.getGradedBy();
        this.gradedAt = examRecord.getGradedAt();
        this.feedback = examRecord.getFeedback();
        this.createdAt = examRecord.getCreatedAt();
        this.updatedAt = examRecord.getUpdatedAt();
        
        // 计算百分比
        if (this.totalPoints != null && this.totalPoints.compareTo(BigDecimal.ZERO) > 0) {
            this.percentage = this.totalScore.divide(this.totalPoints, 4, java.math.RoundingMode.HALF_UP)
                    .multiply(new BigDecimal("100"));
        }
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getExamId() {
        return examId;
    }
    
    public void setExamId(Long examId) {
        this.examId = examId;
    }
    
    public String getExamTitle() {
        return examTitle;
    }
    
    public void setExamTitle(String examTitle) {
        this.examTitle = examTitle;
    }
    
    public Long getUserId() {
        return userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public String getUserName() {
        return userName;
    }
    
    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    public Integer getAttemptNumber() {
        return attemptNumber;
    }
    
    public void setAttemptNumber(Integer attemptNumber) {
        this.attemptNumber = attemptNumber;
    }
    
    public LocalDateTime getStartTime() {
        return startTime;
    }
    
    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }
    
    public LocalDateTime getSubmitTime() {
        return submitTime;
    }
    
    public void setSubmitTime(LocalDateTime submitTime) {
        this.submitTime = submitTime;
    }
    
    public Integer getTimeSpent() {
        return timeSpent;
    }
    
    public void setTimeSpent(Integer timeSpent) {
        this.timeSpent = timeSpent;
    }
    
    public ExamRecordStatus getStatus() {
        return status;
    }
    
    public void setStatus(ExamRecordStatus status) {
        this.status = status;
    }
    
    public BigDecimal getTotalScore() {
        return totalScore;
    }
    
    public void setTotalScore(BigDecimal totalScore) {
        this.totalScore = totalScore;
    }
    
    public BigDecimal getTotalPoints() {
        return totalPoints;
    }
    
    public void setTotalPoints(BigDecimal totalPoints) {
        this.totalPoints = totalPoints;
    }
    
    public BigDecimal getPercentage() {
        return percentage;
    }
    
    public void setPercentage(BigDecimal percentage) {
        this.percentage = percentage;
    }
    
    public PassStatus getPassStatus() {
        return passStatus;
    }
    
    public void setPassStatus(PassStatus passStatus) {
        this.passStatus = passStatus;
    }
    
    public Boolean getAutoGraded() {
        return autoGraded;
    }
    
    public void setAutoGraded(Boolean autoGraded) {
        this.autoGraded = autoGraded;
    }
    
    public Boolean getManualGraded() {
        return manualGraded;
    }
    
    public void setManualGraded(Boolean manualGraded) {
        this.manualGraded = manualGraded;
    }
    
    public Long getGradedBy() {
        return gradedBy;
    }
    
    public void setGradedBy(Long gradedBy) {
        this.gradedBy = gradedBy;
    }
    
    public String getGraderName() {
        return graderName;
    }
    
    public void setGraderName(String graderName) {
        this.graderName = graderName;
    }
    
    public LocalDateTime getGradedAt() {
        return gradedAt;
    }
    
    public void setGradedAt(LocalDateTime gradedAt) {
        this.gradedAt = gradedAt;
    }
    
    public String getFeedback() {
        return feedback;
    }
    
    public void setFeedback(String feedback) {
        this.feedback = feedback;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    public List<ExamAnswerResponse> getAnswers() {
        return answers;
    }
    
    public void setAnswers(List<ExamAnswerResponse> answers) {
        this.answers = answers;
    }
}